﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace WP8Demos.Helpers
{
    public class RelayCommand<T> : ICommand
    {
        private Action<T> command;

        public RelayCommand(Action<T> action) 
        {
            this.command = action;
        }

        public void Execute(object parameter)
        {
            if (command != null)
            {
                command.Invoke((T)parameter);
            }
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }


        public event EventHandler CanExecuteChanged;
    }

    public class RelayCommand : ICommand
    {
        private Action command;
        public event EventHandler CanExecuteChanged;

        public RelayCommand(Action action)
        {
            this.command = action;
        }

        public void Execute(object parameter)
        {
            if (command != null && CanExecuteChanged != null)
            {
                command.Invoke();
            }
        }

        public bool CanExecute(object parameter)
        {
            return this.CanExecuteChanged != null;
        }
    }
}
